/******************************************************************************
COPYRIGHT 2012   : ATECH
Project          : 
Source File Name : sys_micro.h
Group            : SoftWare Team
Author           : 
Date First Issued: 09/09/2012
********************************Documentation**********************************
Purpose -  This file is 
********************************RevisionHistory********************************
_______________________________________________________________________________
Date : MM/DD/YY    Release        Changes Description                  Author
Date : 09/09/2012  1.0                                                   
   
******************************************************************************/

#ifndef sys_micro_h 
#define sys_micro_h 


/* #include */
#include "derivative.h"

/* #define */

#define CLEAR_WATCHDOG      ;
#define RESET_SYSTEM  ((*(volatile unsigned char*)_COP_RST_ADR)= 0x00,(*(volatile unsigned char*)_COP_RST_ADR)= 0x00)

#define NOP()  {asm NOP;} /* No Operation */  

#define ENABLE_INTERRUPTS   {__asm CLI;}  /* enable interrupts */
#define DISABLE_INTERRUPTS  {__asm SEI;}  /* disable interrupts */

/* define macros to maniputlate the S bit */
#define S12_CLEAR_SBIT()   { asm andcc #$7f;}
#define S12_SET_SBIT()     { asm orcc  #$80;}

/* define macros to maniputlate the I bit */
#define S12_CLEAR_IBIT()   { asm andcc #$ef;}
#define S12_SET_IBIT()     { asm orcc #$10; }

#define STOP()   { asm ANDCC #0x7F; asm STOP; }  
//	#define STOP_MODE()   { asm STOP; }    
#define WAIT()              {asm WAI;}          /* Enter wait mode */



/* ERROR for return */
#define ERR_OK           0             /* OK */
#define ERR_SPEED        1             /* This device does not work in the active speed mode. */
#define ERR_RANGE        2             /* Parameter out of range. */
#define ERR_VALUE        3             /* Parameter of incorrect value. */
#define ERR_OVERFLOW     4             /* Timer overflow. */
#define ERR_MATH         5             /* Overflow during evaluation. */
#define ERR_ENABLED      6             /* Device is enabled. */
#define ERR_DISABLED     7             /* Device is disabled. */
#define ERR_BUSY         8             /* Device is busy. */
#define ERR_NOTAVAIL     9             /* Requested value or method not available. */
#define ERR_RXEMPTY      10            /* No data in receiver. */
#define ERR_TXFULL       11            /* Transmitter is full. */
#define ERR_BUSOFF       12            /* Bus not available. */
#define ERR_OVERRUN      13            /* Overrun error is detected. */
#define ERR_FRAMING      14            /* Framing error is detected. */
#define ERR_PARITY       15            /* Parity error is detected. */
#define ERR_NOISE        16            /* Noise error is detected. */
#define ERR_IDLE         17            /* Idle error is detected. */
#define ERR_FAULT        18            /* Fault error is detected. */
#define ERR_BREAK        19            /* Break char is received during communication. */
#define ERR_CRC          20            /* CRC error is detected. */
#define ERR_ARBITR       21            /* A node losts arbitration. This error occurs if two nodes start transmission at the same time. */
#define ERR_PROTECT      22            /* Protection error is detected. */
#define ERR_UNDERFLOW    23            /* Underflow error is detected. */
#define ERR_UNDERRUN     24            /* Underrun error is detected. */
#define ERR_COMMON       25            /* Common error of a device. */
#define ERR_LINSYNC      26            /* LIN synchronization error is detected. */

/* typedef */
#define	_NOPX	{NOP;NOP;NOP;NOP;NOP;} 

#define USE_BUS_8MHz  (0U)
#define USE_BUS_16MHz (1U)
#define USE_BUS_24MHz (2U)


/*
**  Config Marco: USE_BUS_CLK
**  Description:  Config system bus clock
**  Possible Value: USE_BUS_8MHz
**                  USE_BUS_16MHz
**
*/
#define USE_BUS_CLK USE_BUS_16MHz



/* typedef */

/* Class definitions */

/* Function prototypes */


/**************************end of sys_micro.h*************************************/
#endif


/******************************************************************************
 Revision Notes:

For each change to this file, be sure to record:
1. Who made the change and when the change was made.
2. Why the change was made and the intended result.

  Date     By     Reason For Change
mm/dd/yy  XXX     -----------------

******************************************************************************/
